home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / maximus / mul100.zip / PHONEFIX.SCR < prev    next >
Text File  |  1993-02-01  |  3KB  |  96 lines

  1.  
  2. // PHONEFIX.SCR  --  Maximus User Base Phone Formatter  --  Version 1.00
  3. //
  4. // Script program for MUL - the Maximus User Language
  5. // MUL is (C) Copyright 1990-93 by CodeLand Australia
  6.  
  7. // PhoneFix formats the telephone field in all user file records, using
  8. // a supplied pattern mask (the phonemask string below). Edit the
  9. // phonemask string to match your local requirements.
  10.  
  11. char *ufile = "USER.BBS";                   // Path & name of Maximus user file
  12. //char *ufile = "C:\\BBS\\USER.BBS";        // Path & name of Maximus user file
  13. char *phonemask = "(###) ###-####";         // Format string
  14.  
  15. char *banner = "PHONEFIX v1.00";            // Script banner
  16. char *desc = "Maximus Phone Formatter";     // Description
  17.  
  18. // Optionally post a message to accounts without a phone entry
  19. char *warnpho = "MsgPost -TC:\\Util\\WarnPho.Txt \"-F%s\"";
  20.  
  21. main ()                                     // Main program
  22. {
  23.     int rec=2;                              // Starting record number
  24.     char buf[128];                          // Work buffer
  25.  
  26.     printf ("\n%s - %s\n\n",banner,desc);   // Announce
  27.  
  28.     if (!BaseOpen (ufile)) {
  29.         printf ("ERROR opening user file %s\n",ufile);
  30.         exit ();
  31.     }
  32.  
  33.     // Process all records
  34.     while (BaseRead (rec)) {
  35.         if (!USRflagdel) { // Only non-deleted records
  36.             if (fix_phone (rec)) BaseWrite (rec);
  37.             // else { sprintf (buf,warnpho,USRname); system (buf); }
  38.         }
  39.         ++rec;
  40.     }
  41.  
  42.     BaseClose ();                           // Close the user base
  43.     saybibi ();                             // Was it good for you too?
  44. }
  45.  
  46. fix_phone (int rec)                         // Adjust user phone field
  47. {
  48.     char *p, *q, newphone[20], oldphone[20];
  49.  
  50.     // Get the data
  51.     strcpy (newphone,phonemask); reverse (newphone);
  52.     strcpy (oldphone,USRphone);  reverse (oldphone);
  53.  
  54.     if (!oldphone[0]) {                    // Abort if no entry
  55.         printf("%04u %-25s NO PHONE ENTRY!\n",rec,USRname);
  56.         return 0;
  57.     }
  58.  
  59.     p=oldphone; q=newphone;                 // Point at last characters
  60.  
  61.     while (TRUE) {
  62.         while (*p && !isdigit (*p)) p++;    // Skip non digits
  63.         if (!*p) break;                     // End of string
  64.  
  65.         while (*q && *q!='#') q++;          // Skip all except # characters
  66.         if (!*q) break;                     // End of format string
  67.  
  68.         *q++=*p++;                          // Transfer the number
  69.     }
  70.  
  71.     // Out of format string
  72.     if (!*q) while (*p) *q++=*p++;          // Transfer the rest
  73.  
  74.     // Out of numerics
  75.     else while (*q) {                       
  76.         if (*q=='#') *q=' ';                // Blank the left over format chars
  77.         q++;
  78.     }
  79.     *q='\0';                                // Terminate the output
  80.  
  81.     newphone[14]='\0'; reverse (newphone);
  82.     printf("%04u %-25s %-14s => %s\n",rec,USRname,USRphone,newphone);
  83.     strcpy (USRphone,newphone);
  84.  
  85.     return 1;
  86. }
  87.  
  88. // Byebye
  89. saybibi ()
  90. {                             
  91.     puts ("\nPhoneFix done!\n");
  92. }
  93.  
  94. // End of script
  95.  
  96.